/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelXY.java
 *
 * Created on 18/09/2011, 23:51:06
 */
package visao;

import java.awt.Color;
import java.awt.Graphics;
import modelo.objeto2d.Aresta2d;
import modelo.objeto2d.Objeto2d;

/**
 *
 * @author TyTu
 */
public class JPanelXY extends javax.swing.JPanel {

    /** Creates new form JPanelXY */
    public JPanelXY(Objeto2d o) {
        this.obj2d=o;
        initComponents();        
    }
    
    private Objeto2d obj2d;

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        desenha();
    }
    
    public void desenha() {
        try{            
            Graphics g = this.getGraphics();
            g.setColor(Color.white);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            g.setColor(Color.BLACK);
            
            for (Aresta2d aresta : obj2d.getArestas()) {
                this.getGraphics().drawLine(
                        (int) aresta.getP1().getX(),
                        (int) aresta.getP1().getY(),
                        (int) aresta.getP2().getX(),
                        (int) aresta.getP2().getY());
            }
        }catch(Exception e){
            
        }
    }
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
